﻿using iTelluro.Explorer.Infrastructure.CrossCutting.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Globalization;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace iTelluro.Explorer.Infrastructure.CrossCutting.NetFramework.Logging
{
    public sealed class Log4net : ILogger
    {
        #region 成员变量和构造函数

        ILog log;
        public Log4net()
        {
            log = LogManager.GetLogger("地灾监测产品");
        }
        public Log4net(string className)
        {
            log = LogManager.GetLogger(className);
        }
        #endregion

        #region ILogger 成员

        public void Debug(string message, params object[] args)
        {
            log.Debug(getMessage(message,args));
        }

        public void Debug(string message, Exception exception, params object[] args)
        {
            log.Debug(getMessage(message, args), exception);
        }

        public void Debug(object item)
        {
            if (item != null)
            {
                log.Debug(item.ToString());
            }
        }

        public void Fatal(string message, params object[] args)
        {
            log.Fatal(getMessage(message, args));
        }

        public void Fatal(string message, Exception exception, params object[] args)
        {
            log.Fatal(getMessage(message, args), exception);
        }

        public void LogInfo(string message, params object[] args)
        {
                log.Info(getMessage(message, args));
        }

        public void LogWarning(string message, params object[] args)
        {
            log.Warn(getMessage(message, args));
        }

        public void LogError(string message, params object[] args)
        {
            log.Error(getMessage(message, args));
        }

        public void LogError(string message, Exception exception, params object[] args)
        {
            log.Error(getMessage(message, args), exception);
        }
        #endregion

        #region 私有函数
        private string getMessage(string message, object[] args)
        {
            if (args != null)
                return string.Format(CultureInfo.InvariantCulture, message, args);
            else
                return message;
        }
        #endregion
    }
}
